package com.wanghlme.day26.web;

import com.alibaba.fastjson.JSONArray;
import com.wanghlme.day26.pojo.Emp;
import com.wanghlme.day26.service.IEmpService;
import com.wanghlme.day26.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/listAll")
public class ListAllAction extends HttpServlet {
    private IEmpService empService;

    public ListAllAction() {
        empService = new EmpServiceImpl();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Emp> list = empService.listAllEmployee();
        PrintWriter out = resp.getWriter();
//        out.print("{\"code\":0,\"msg\":\"\",\"count\":" + list.size() + ",\"data\":" + JSONArray.toJSONString(list) + "}");
        out.print(JSONArray.toJSONString(list));
        out.flush();
        out.close();
    }
}
